package com.song.day01protobuf编码解码.server;

import com.song.day01protobuf编码解码.PackageMessageProto;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.handler.timeout.IdleState;
import io.netty.handler.timeout.IdleStateEvent;

//SimpleChannelInboundHandler<PackageMessage>
public class CenterHandler  extends  ChannelInboundHandlerAdapter{

	@Override
	public void userEventTriggered(ChannelHandlerContext ctx, Object evt)
			throws Exception {
		// TODO Auto-generated method stub
		super.userEventTriggered(ctx, evt);
		
		if( evt instanceof IdleStateEvent)
		{
			IdleStateEvent event = (IdleStateEvent) evt;
			if(event.state()  == IdleState.READER_IDLE)
			{
				System.out.println("---READER_IDLE---");
			}else if(event.state() == IdleState.WRITER_IDLE)
			{
				System.out.println("---WRITER_IDLE---");
			}
			
		}
		
	}

	
	
	public void channelRead(ChannelHandlerContext ctx, Object obj)
			throws Exception {
		
		PackageMessageProto.PackageMessage   pmsg =  (PackageMessageProto.PackageMessage) obj;
		System.out.println("注册中心接受数据  ----" + pmsg);
	}


	@Override
	public void channelReadComplete(ChannelHandlerContext ctx) {
		ctx.flush();
	}

	@Override
	public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
		System.out.println(cause.getCause());
		ctx.close();
	}


}
